package com.gxnzd.communityelderly.commom;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * ClassName: MyMetaObjectHandler
 * Package: com.gxnzd.communityelderly.commom
 * Description:
 *
 * @Author 胡海峰
 * @Create 2024/10/15 14:09
 * @Version 1.0
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //取到当前线程上的用户id
        Long empId = BaseContext.getThreadLocal();
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("createUser", empId);
        metaObject.setValue("updateTime", LocalDateTime.now() );
        metaObject.setValue("updateUser",empId);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //取到当前线程上的用户id
        Long empId = BaseContext.getThreadLocal();
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",  empId);
    }
}
